package algorithms.sedgewick.part1.sort;



import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Brute {
	private static final String DELIM = " -> ";

	public static void main(String[] args) throws NumberFormatException, IOException {
		if(args==null ||
				args.length<1){
			throw new IllegalArgumentException();
		}
		StdDraw.setXscale(0, 32768);
		StdDraw.setYscale(0, 32768) ;
		BufferedReader br = new BufferedReader(new FileReader(args[0]));
		int noOfPairs = Integer.parseInt(br.readLine().trim());
		String str;
		List<Point> pointList = new ArrayList<Point>(noOfPairs);
		Scanner scan;
		while((str = br.readLine())!=null){
			try{
				scan = new Scanner(str);
				//strArr = str.split("[\\s\\t]");
				//pointList.add(new Point(Integer.parseInt(strArr[0].trim()), Integer.parseInt(strArr[1].trim())));
				pointList.add(new Point(scan.nextInt(), scan.nextInt()));
				scan.close();
			}catch(RuntimeException r){}
		}
		for(Point p:pointList){
			p.draw();
		}
		br.close();
		Collections.sort(pointList);
		findCollinearSegments(pointList);
	}
	private static final void findCollinearSegments(List<Point> pointList){
		double slope1,slope2, slope3;
		int firstLoopSize=pointList.size()-3, secondLoopSize = firstLoopSize+1,thirdLoopSize = firstLoopSize+2;
		Point firstPoint, secondPoint, thirdPoint, fourthPoint;
		Point[] arr = new Point[4];

		for(int i=0;i<firstLoopSize;i++){
			firstPoint = pointList.get(i);
			for(int j=i+1;j<secondLoopSize;j++){
				secondPoint = pointList.get(j);
				slope1 =firstPoint.slopeTo(secondPoint);
				for(int k=j+1;k<thirdLoopSize;k++){
					thirdPoint = pointList.get(k);
					slope2 = firstPoint.slopeTo(thirdPoint);
					if(slope1!=slope2){
						continue;
					}
					for(int l=k+1;l<pointList.size();l++){
						fourthPoint = pointList.get(l);
						slope3 = firstPoint.slopeTo(fourthPoint);
						if(slope3==slope1 &&
								slope3 == slope2){

							arr[0] = firstPoint;
							arr[1] = secondPoint;
							arr[2] = thirdPoint;
							arr[3] = fourthPoint;
							System.out.println(arr[0]+DELIM+arr[1]+DELIM+arr[2]+DELIM+arr[3]);
							/*arr[0].draw();
							arr[1].draw();
							arr[2].draw();
							arr[3].draw();*/
							arr[0].drawTo(arr[3]);

						}
					}
				}
			}
		}
	}

}
